<template>
	<div class="addProject business-workAdd">
		<div class="top_part">
			<p>{{detailData.planCode}} / {{detailData.planTypeCn}} / {{detailData.planName}} / {{detailData.gradeValue}} / {{detailData.thNumber}}（万支） </p>
			<div class="_right">
				<div class="text-formList">
					<span class="text_left">产量件数：</span>
					<span class="text_right">{{detailData.taskCount}}</span>
				</div>
				<div class="text-formList">
					<span class="text_left">产量万支：</span>
					<span class="text_right">{{detailData.totalNum}}</span>
				</div>
			</div>
		</div>
		<div class="tableList" >
			<table>
				<tr>
					<th width="25%">包装机号</th>
					<th width="25%">报工时间</th>
					<th width="25%">箱号</th>
					<th width="25%">操作工</th>
					<th width="20%">操作</th>
					<!--<th width="25%">料源</th>-->
				</tr>
			</table>
		</div>
		<div class="over_t tableList" style="margin-top: 0;">
			<table v-loading="tableLoading">
				<tr v-for="(item, index) in tableList" :key="index" class="add_Table">
					<td width="25%">{{detailData.deviceCode}}</td>
					<td width="25%">{{item.createTimeFt}}</td>
					<td width="25%">{{item.boxCode}}</td>
					<td width="25%">{{item.userName}}</td>
					<td width="20%"><span style="color: #1890ff;cursor: pointer;" @click="deleteBoxCode(item)">删除</span></td>
					<!--<td width="25%"></td>-->
				</tr>
			</table>
		</div>
	</div>
</template>

<script>
	export default {
		props: ['editData'],
		data() {
			return {
				detailData:{
					id:'',
					planCode:'',
					planId:'',
					planTypeCn:'',
					planName:'',
					gradeValue:'',
					thNumber:'',
					deviceCode:'',
				},
				tableList: [{}],
				tableLoading:false
			}
		},
		methods: {
			deleteBoxCode(item){
				let self = this;
				self.$confirm('确定删除该箱码？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let param = {taskId:item.taskId,planId:item.planId,boxCode:item.boxCode}
					self.$http({
						url: "/jinl/psRelate/deleteOnDutyProductCodeBox",
						method: "post",
						params:param
					}).then(resp => {
						if (resp.success) {
							self.$message.success('删除成功！');
							self.getOnDutyProductPersonList();
							let taskCount = parseInt(self.detailData.taskCount) -1;
							self.detailData.taskCount  =taskCount +'';
							self.detailData.totalNum = (taskCount*parseFloat(self.detailData.thNumber)).toFixed(2)+'';
							self.$eventBus.$emit('refreshOnDutyProductPersonList');
						}
					});
				})
			},
			getOnDutyProductPersonList() {
				let self = this;
				self.tableLoading = true;
				self.tableList = [];
				self.$http({
					url: "/jinl/psRelate/getProductStorageRelateListByTaskId",
					method: "post",
					params:{taskId:self.detailData.id,planId:self.detailData.planId}
				}).then(resp => {
					if (resp.success) {
						let tableList = [];
						console.log(resp.result)
						for(let data of (resp.result||[])){
							if(data.taskId == self.detailData.id && data.userName == self.detailData.userName){
								tableList.push(data)
							}
						}
						self.tableList = tableList;
						self.tableLoading = false;

					}
				});
			},
		},

		watch:{
			editData(val) {
				this.detailData = val;
				console.log(val)
				this.getOnDutyProductPersonList();
			},
		},

		mounted() {

		}
	};
</script>

<style lang="scss" scoped>
	@import "@/style/dialog.scss";

	.top_part {
		display: flex;
		justify-content: space-between;

		p {
			line-height: 32px;
		}

		._right {
			display: flex;

			.text-formList {
				margin-left: 15px;

				.text_right {
					color: #2196f3;
				}
			}
		}
	}

	.over_t {
		height: 190px;
		overflow-y: auto;
	}
</style>